import type { Request } from 'express'
import { todoService } from '@server/services/todo-service'
import { ApiResponse } from '@data/api'
import { NotFoundError } from '@server/error/errors'

export default async function restoreTodo(request: Request) {
  const id = request.params.id

  const todo = await todoService.restoreTodo(id)

  if (!todo) {
    throw new NotFoundError('Todo not found or not deleted')
  }

  const response: ApiResponse = {
    success: true,
    data: todo,
    message: 'Todo restored successfully',
  }

  return response
}
